Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Event Dispatcher and tests. r=gmarty #115

Merged
merged 1 commit into from
Apr 22, 2016
Merged

Import Event Dispatcher and tests. r=gmarty #115

merged 1 commit into from
Apr 22, 2016

Conversation

azasypkin
Copy link
Member

No description provided.

* @param {string} eventName Name of the event to check listeners for.
* @returns {boolean}
*/
hasListeners(eventName) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feelings about this method - but it simplifies a lot my next PR, so I've added this one. If in the future I find better approach to know that I can shutdown the bus (or something that depends on the bus) if there is no listeners anymore, I would probably try to get rid of this method.

@azasypkin
Copy link
Member Author

@gmarty r?

@@ -169,7 +157,8 @@ export default class EventDispatcher {

/**
* Removes all registered listeners for the specified event.
* @param {string} eventName Name of the event to remove all listeners for.
*
* @param {string} [eventName] Name of the event to remove all listeners for.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Do the brackets around the param name for optional? If we use Closure Compiler flavour of JSDoc, you can indicate optional params with a = (see https://developers.google.com/closure/compiler/docs/js-for-compiler#types):

/**
 * Removes all registered listeners for the specified event.
 *
 * @param {string=} eventName Name of the event to remove all listeners for.
 */

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, does webstorm + enabled ESLint recognize {string=} as optional parameter for you?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me on WebStorm but I don't think I set up ESLint properly. If it's a bug maybe we should fill a ticket in WebStorm or ESLint.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, likely a bug somewhere, will file one if not forget :)

@gmarty
Copy link
Collaborator

gmarty commented Apr 22, 2016

Note on event-dispatcher.js: this file looks good. I would have called the ensure*() functions something like assert*(). But apart from a couple of nits, I'm happy with it.
Reviewing the rest of the PR now.

@@ -0,0 +1,423 @@
import EventDispatcher from 'js/lib/foxbox/event-dispatcher';

describe('EventDispatcher >', function () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Do we have a good reason to use function () { as opposed to () => { in the test files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, "historically" I used function in tests and where I don't need to grab context (likely browser knows that and doesn't do anything especial, but I don't know for sure), so just used to do it.

Do you think we should use arrows here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just an idea.
That would result in a more readable file, but that's debatable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll keep like it's currently, but we can discuss this later, I don't have a preference actually

@gmarty
Copy link
Collaborator

gmarty commented Apr 22, 2016

r+ when you add a test case for hasListeners.
I like that we get all those tests for free!

@azasypkin
Copy link
Member Author

I would have called the ensure_() functions something like assert_()

Yeah, maybe assert*-like name is better, I'll rename!

@azasypkin
Copy link
Member Author

r+ when you add a test case for hasListeners.

Ha-ha, I knew you'll notice that :) Will add few tests for this new method as well.

I like that we get all those tests for free!

Almost for free :p It required some routine describe\it\before\after\const\let-fication :)

@azasypkin
Copy link
Member Author

Nits fixed, travis is green - merging!

@azasypkin azasypkin merged commit ee6997d into fxbox:master Apr 22, 2016
@azasypkin azasypkin deleted the issue-xxx-import-event-dispatcher branch April 22, 2016 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants